package cn.dapeng.interview;

import java.util.PriorityQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.SynchronousQueue;

/**
 * 容量为0的同步队列，主要用户两个线程之间的信息交换
 * 类似Exchange同步类
 */
public class SynchronousQueue_T01 {

    public static void main(String[] args) throws InterruptedException {
        BlockingQueue<String> queue = new SynchronousQueue<>();



        new Thread(() -> {
            try {
                System.out.println(queue.take());
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }).start();

        //queue.put("t1"); // 一直等待
        queue.offer("t2"); // 添加失败 返回false
        queue.add("t2"); // 抛异常
        System.out.println(queue.size());
    }
}
